package com.workoutgrabber.model;

import org.jdom.Element;
import org.joda.time.DateTime;

public class CardioExercise extends Exercise {
	private Double duration;
	
	private CardioExercise(String name, DateTime date, Double duration){
		this.name = name;
		this.date = date;
		this.duration = duration;
	}
	
	public static CardioExercise getInstance(String name, DateTime date, Double duration){
		return new CardioExercise(name, date, duration);
	}
	
	public Double getDuration() {
		return duration;
	}

	@Override
	public Element getAsXML() {
		Element exerciseElement = new Element("exercise");
		exerciseElement.setAttribute("type", "cardioExercise");
		
		Element nameElement = new Element("name");
		nameElement.setText(this.name);
		
		Element dateElement = new Element("date");
		dateElement.setText(this.date.toString());
		
		Element durationElement = new Element("duration");
		durationElement.setText(duration.toString());
		
		exerciseElement.addContent(nameElement);
		exerciseElement.addContent(dateElement);
		exerciseElement.addContent(durationElement);
		
		return exerciseElement;
	}
	
	@Override
	public String toString() {
		StringBuilder toString = new StringBuilder();
		toString.append("Cardio exercise. Name: ");
		toString.append(name);
		toString.append(" Date: ");
		toString.append(date);
		toString.append(" Duration: ");
		toString.append(duration);
		
		return toString.toString();
	}
}
